package com.bestv.search.engine.command;

import org.compass.core.Compass;
import org.compass.core.CompassTemplate;
import org.springframework.beans.factory.InitializingBean;

public abstract class AbstractSearchCommand implements InitializingBean {

    private Compass compass;

    private CompassTemplate compassTemplate;

    public void afterPropertiesSet() throws Exception {
        if (compass == null) {
            throw new IllegalArgumentException("Must set compass property");
        }
        this.compassTemplate = new CompassTemplate(compass);
    }

    /**
     * Returns <code>Compass</code> instance.
     *
     * @return The compass instance.
     */
    public Compass getCompass() {
        return compass;
    }

    /**
     * Sets the <code>Compass</code> instance.
     *
     * @param compass
     */
    public void setCompass(Compass compass) {
        this.compass = compass;
    }

    /**
     * Returns a <code>CompassTemplate</code> that wraps the injected
     * <code>Compass</code> instance.
     *
     * @return Compass template that wraps the injected Compass instance.
     */
    protected CompassTemplate getCompassTemplate() {
        return this.compassTemplate;
    }

    public void setCompassTemplate(CompassTemplate compassTemplate) {
        this.compassTemplate = compassTemplate;
    }
}
